<template>
    <exPubTable ref="sumTable" :cfg.sync="sumcfg" :exData="sumList" @getDataList="querySumInfo"  :diffHeight="30" :defPageSize="100" :show-summary="true"></exPubTable>
</template>


<script>

export default {
    data() {
        var that =this;
        return {
            totalMoney: 0,
            sumList:[],
            sumcfg:{
                showIndex: true,
                columns: [
                    {prop:"",label:"数据合计(查询全部)",align:"center",
                        columns:[
                            {prop:"code",label:"代码",width:150,sortable:true},
                            {prop:"name",label:"名称",width:150,sortable:true},
                            {prop:"amount",label:"持仓数量",width:150,sortable:true,sumType:"add"},
                            {prop:"total",label:"总盈利",width:150,sortable:true,sumType:"add",formatter:this.fixed2,getColor(s){return that.getRateColor(s.row.total)}},
                            {prop:"totalFee",label:"总手续费",width:150,sumType:"add",formatter:this.fixed2},
                        ]
                    }
                ],
            },
        }
    },

    mounted() {
    },
    inject:["getQueryInfo"],

    methods: {
        reQuery(){
            if(this.$refs.sumTable) this.$refs.sumTable.reQuery();
        },
        querySumInfo(){
            var opername = "getSumInfo";
            this.registerListen(this,opername,(res)=>{
                if(res.succ){
                    this.sumList = res.data;
                }else{
                    this.$message.error("查询异常:"+res.err)
                }
            });
            
            var param = {type:opername,name:opername,objInfo:{}};
            param.execSql=true;
            param.sql=`select a.code code,a.name name,sum(a.amount) amount,
            sum(money)+ ifnull(b.zxsz,0) total
            ,sum(fee1)+sum(fee2)+sum(fee3)+sum(fee4) totalFee FROM tradehis a 
            left outer join store b on b.code=a.code and b.day = (select max(day) from store)
            GROUP BY a.code order by total desc`;
            electron.ipcRenderer.send("doSql",param)
        },
    }
    
}
</script>

<style lang="less">

</style>
